package top.continew.admin.sport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;

import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;
import top.continew.admin.sport.mapper.ProjectRefereeMapper;
import top.continew.admin.sport.model.entity.ProjectRefereeDO;
import top.continew.admin.sport.model.query.ProjectRefereeQuery;
import top.continew.admin.sport.model.req.ProjectRefereeReq;
import top.continew.admin.sport.model.resp.ProjectRefereeDetailResp;
import top.continew.admin.sport.model.resp.ProjectRefereeResp;
import top.continew.admin.sport.service.ProjectRefereeService;

import java.util.List;

/**
 * 项目裁判业务实现
 *
 * @author xiahaike
 * @since 2024/09/15 09:22
 */
@Service
@RequiredArgsConstructor
public class ProjectRefereeServiceImpl extends BaseServiceImpl<ProjectRefereeMapper, ProjectRefereeDO, ProjectRefereeResp, ProjectRefereeDetailResp, ProjectRefereeQuery, ProjectRefereeReq> implements ProjectRefereeService {

    @Resource
    private ProjectRefereeMapper projectRefereeMapper;

    @Override
    public PageResp<ProjectRefereeResp> myPage(ProjectRefereeQuery projectRefereeQuery, PageQuery pageQuery) {
        QueryWrapper<ProjectRefereeDO> queryWrapper = new QueryWrapper<>();
        IPage<ProjectRefereeResp> page = projectRefereeMapper.myPage(pageQuery.toPage(), queryWrapper, projectRefereeQuery.getProjectId());
        return PageResp.build(page);
    }

    @Override
    public void batchAdd(Long projectId, List<Long> refereeIds) {
        List<ProjectRefereeDO> projectRefereeReqs = refereeIds.stream().map(refereeId -> {
            ProjectRefereeDO projectRefereeReq = new ProjectRefereeDO();
            projectRefereeReq.setProjectId(projectId);
            projectRefereeReq.setRefereeId(refereeId);
            return projectRefereeReq;
        }).toList();
        projectRefereeMapper.insertBatch(projectRefereeReqs);
    }
}